package org.example.hw.model;

import javax.persistence.Entity;
import javax.persistence.Table;

import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.hibernate.envers.Audited;
import org.hibernate.validator.constraints.NotBlank;

@Entity
@Table(name="HW_COMMENT")
@Audited
public class Comment extends AbstractEntity {

	@NotBlank
	private String text;
	
	
	public Comment() {
		
	}

	
	public String getText() {
		return text;
	}

	public void setText(String text) {
		this.text = text;
	}
	
	
	@Override
	public int hashCode() {
		return new HashCodeBuilder().
				append(super.hashCode()).
				append(text).
				hashCode();
	}
	
	@Override
	public boolean equals(Object obj) {
		if (obj == null) { return false; }
		if (obj == this) { return true; }
		if (obj.getClass() != getClass()) {
			return false;
		}

		final Comment otherComment = (Comment) obj;

		return new EqualsBuilder().
				appendSuper(super.equals(obj)).
				append(text, otherComment.getText()).
				isEquals();
	}
	
	@Override
	public String toString() {
		return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE).
				append("text", text).
				append(super.toString()).
				toString();
	}
	
}
